/**
 * @description XOMS中的确认框
 * @author yanxiaoe
 * @param {object} {
 * 	title: 确认弹出框的title,
 * 	content: 确认框的内容
 * 	callback: {
 * 		ok: 确定按钮的回调函数
 * 		cancel: 取消按钮的回调函数
 * 	}
 * }
 * @example XOMS.confirm(param);
 */
define(['jquery', 'XOMS', 'jquery.ui', 'xoms.lang.common'], function($, XOMS) {
	var Lang = XOMS.Lang.common;
	var defaultOptions = {
		title: Lang.button.confirmTitle,
		content: Lang.content.defaultTips,
		callback: {
			ok: function() {},
			cancel: function() {}
		}
	};
	
	XOMS.confirm = function(options) {
		var _options = $.extend({}, defaultOptions, options);
		
		var dialogHtml = '<div id="confirm-dialog" title="' + _options.title + '" style="display: none;">' +
			'<div class="xoms-confirm-content">' + _options.content + '</div>' + 
		'</div>',
		oldDialog = $('#confirm-dialog');
		if(oldDialog.length > 0) {
			oldDialog.attr('title', _options.title);
			oldDialog.find('.xoms-confirm-content').html(_options.content);
		} else {
			$('body').append(dialogHtml);
		}
		var dialog = $('#confirm-dialog').dialog({
			autoOpen: true,
			resizable: false,
			width: 400,
			height: 200,
			modal: true,
			buttons: [
			          {
			        	  text: Lang.button.ok,
			        	  click: function() {
								if(!!_options.callback.ok) {
									_options.callback.ok.call(this);
								};
								$( this ).dialog( "destroy" );
							}
			          },
			          {
			        	  text: Lang.button.cancel,
			        	  click: function() {
			        		  if(!!_options.callback.cancel) {
									_options.callback.cancel();
								};
								$( this ).dialog( "destroy" );
			        	  }
			          }
			          ]
		});
	};
	
	return XOMS.confirm;
});